﻿<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>账单审核</title>
    <link rel="stylesheet" type="text/css" href="../Content/Css/OperaMasksUI/default/om-all.css" />
    <link rel="stylesheet" type="text/css" href="../Content/Css/list.css" />
    <script type="text/javascript" src="../Scripts/jquery.1.6.3.min.js"></script>
    <script type="text/javascript" src="../Scripts/json2.js"></script>
    <script type="text/javascript" src="../Scripts/common.js"></script>
    <script type="text/javascript" src="../Scripts/OperaMasksUI/operamasks-ui.min.js"></script>
    <script type="text/javascript" src="../Scripts/Plugin/jquery.form.js"></script>
    <script type="text/javascript" src="../Scripts/OperaMasksUI/Plugin/om-yj-container.js"></script>
    <script type="text/javascript" src="../Scripts/Plugin/artDialog4.1.7/jquery.artDialog.js?skin=default"></script>
    <script type="text/javascript" src="../Scripts/Plugin/artDialog4.1.7/plugins/iframeTools.js"></script>
    <script type="text/javascript" src="../Scripts/banBackSpace.js"></script>
    <script type="text/javascript">
        var detailPanel, listGrid, incomeGrid, costGrid, colData, incomeColData, costColData, searchPanel, defaultSort, defaultWhere, validatorForm, submitForm, currentUID, currentGIndex = -1, genRenderCheckbox, genRenderDateformat;
        var showSearchPanel, showToolBar, showSubToolBar , detailForm, goOn = true, DoFlag = true, ifh;
        var actionRoot = "../handler/ajax.ashx?type=AjaxSystem", comboxBankData = [], comboxTypeData = [], comboxStatusData = [], genRenderDateformat, genRenderDateformatSS;

        $(document).ready(function () {
            $.ajax({
                cache: false, async: false,
                url: '../handler/ajax.ashx?type=AjaxSystem&method=loginIn',
                dataType: 'json', type: 'post',
                beforeSend: function () {
                    $.omMessageBox.waiting({
                        title: '请等待',
                        content: '服务器正在加载用户信息,请稍后...'
                    });
                },
                complete: function () {
                    $.omMessageBox.waiting("close");
                },
                success: function (data) {
                    if (data.IsError) {
                        goOn = false;
                        $.omMessageBox.alert({
                            content: '发现错误<BR>：' + data.Message,
                            onClose: function () {
                                window.top.location.href = decodeURIComponent("../Index.aspx");
                            }
                        });
                    }
                    else {
                        goOn = true;
                        currentUID = data.Data.userid
                    }
                },
                error: function (result) {
                    goOn = false;
                    $.omMessageBox.alert({
                        content: '发现错误<BR>：' + result.status,
                        onClose: function () {
                            window.top.location.href = decodeURIComponent("Index.aspx");
                        }
                    });
                }
            });
            var element = $('body').omBorderLayout({
                fit: true,
                spacing: 0,
                panels: [
                {
                    id: "center-panel",
                    header: false,
                    title: "中间模块",
                    region: "center"
                }, {
                    id: "west-panel",
                    resizable: true,
                    collapsible: true,
                    title: "<span style='color:#15428B;font-weight: bold;padding:6px;'>查询条件</span>",
                    region: "west",
                    width: 230
                },
                {
                    id: "south-panel",
                    region: "south",
                    header: false,
                    resizable: false,
                    collapsible: false,
                    height: 50
                },
                {
                    id: "east-panel",
                    region: "east",
                    header: false,
                    resizable: false,
                    collapsible: false,
                    width: 500
                }
                ]
            });
            showSearchPanel();
            colData = [
                { header: '账单编号', name: 'BillNo', width: 100, align: 'center' },
                { header: '账单状态', name: 'BillStatus', width: 60, align: 'center' },
                { header: '顺序号', name: 'SeqNo', width: 30, align: 'right'},
                { header: '一级部门', name: 'DeptName1', width: 80, align: 'center' },
                { header: '二级部门', name: 'DeptName2', width: 80, align: 'center' },
                { header: '客户名称', name: 'CustomerName', width: 80, align: 'left' },
                { header: '业务流水号', name: 'OrderNo', width: 80, align: 'left' },
                { header: '业务类型', name: 'OrderType', width: 60, align: 'left' },
                { header: '客户名称', name: 'Currency', width: 80, align: 'left' },
                { header: '业务流水号', name: 'Exchange', width: 80, align: 'left' },
                { header: '业务类型', name: 'Amount', width: 60, align: 'left' },
                { header: '收入CNY', name: 'IncomeCNY', width: 60, align: 'left' },
                { header: '成本CNY', name: 'CostCNY', width: 60, align: 'left' },
                { header: '毛利CNY', name: 'ProfitCNY', width: 60, align: 'left' },
                { header: '对账', name: 'IsCollate', width: 30, align: 'center', renderer: genRenderCheckbox },
                { header: '对账时间', name: 'CollateDate', width: 120, align: 'center', renderer: genRenderDateformat },
                { header: '对账人', name: 'UserCollate', width: 80, align: 'center' },
                { header: '对账编号', name: 'CollateNo', width: 80, align: 'center' },
                { header: '提交', name: 'IsCommit', width: 30, align: 'center', renderer: genRenderCheckbox },
                { header: '提交时间', name: 'CommitDate', width: 120, align: 'center', renderer: genRenderDateformat },
                { header: '提交人', name: 'UserCommit', width: 80, align: 'center' },
                { header: '审核', name: 'IsVerify', width: 30, align: 'center', renderer: genRenderCheckbox },
                { header: '审核时间', name: 'VerifyDate', width: 120, align: 'center', renderer: genRenderDateformat },
                { header: '审核人', name: 'UserVerify', width: 80, align: 'center' },
                { header: '备注', name: 'Note', width: 80, align: 'center' },
                { header: '创建人', name: 'UserCreate', width: 100, align: 'center'},
                { header: '创建时间', name: 'CreateDate', width: 120, align: 'center', renderer: genRenderDateformat},
                { header: '修改人', name: 'UserModify', width: 100, align: 'center'},
                { header: '修改时间', name: 'ModifyDate', width: 120, align: 'center', renderer: genRenderDateformat}
            ];
            incomeColData = [
                { header: '账单编号', name: 'BillNo', width: 100, align: 'center' },
                { header: '顺序号', name: 'SeqNO', width: 30, align: 'right'},
                { header: '费用项目', name: 'FeeType', width: 80, align: 'left' },
                { header: '单价', name: 'Price', width: 50, align: 'right' },
                { header: '数量', name: 'Qty', width: 30, align: 'right' },
                { header: '金额', name: 'Income', width: 50, align: 'right' },
            ];
            costColData = [
                { header: '账单编号', name: 'BillNo', width: 100, align: 'center' },
                { header: '顺序号', name: 'SeqNO', width: 30, align: 'right'},
                { header: '供应商', name: 'SupplyName', width: 80, align: 'left' },
                { header: '费用项目', name: 'FeeType', width: 80, align: 'left' },
                { header: '单价', name: 'Price', width: 50, align: 'right'},
                { header: '数量', name: 'Qty', width: 30, align: 'right' },
                { header: '币种', name: 'Currency', width: 30, align: 'left'},
                { header: '汇率', name: 'Exchange', width: 50, align: 'right' },
                { header: '金额', name: 'Cost', width: 50, align: 'right' },
                { header: '金额CNY', name: 'CostCNY', width: 50, align: 'right' }
        ];
            defaultSort = { sortby: 'UID', sortdir: 'ASC' };
            defaultWhere = { where: ' 1=1 ' };
            listGrid = $('#listgrid').omGrid({
                width: '100%',
                height: 'fit',
                singleSelect: false,
                editMode: 'insert',
                //title: '<span style="color:#15428B;font-weight: bold;padding:6px;">账单列表</span><span id="button-zddelete" style="float:right;text-align:center;cursor:pointer;"><img src="../Content/Images/List/delete.png" width="16" height="16" style="border:none;vertical-align:middle" />删除</span><span id="button-zdedit" style="float:right;text-align:center;cursor:pointer;"><img src="../Content/Images/List/edit.png" width="16" height="16" style="border:none;vertical-align:middle" />编辑</span><span id="button-zdcopy" style="float:right;text-align:center;cursor:pointer;"><img src="../Content/Images/List/copy.png" width="16" height="16" style="border:none;vertical-align:middle" />拷贝</span>',
                limit: 20,
                onRowClick: function (rowIndex, rowData, event) {
                    incomeGrid.omGrid({
                        extraData: $.extend({ where: " BillNo = '" + rowData.BillNo + "'" }, { sortby: 'UID', sortdir: 'ASC' }),
                        dataSource: '../Handler/grid.ashx?view=vIncome',
                    });
                    costGrid.omGrid({
                        extraData: $.extend({ where: " BillNo = '" + rowData.BillNo + "'" }, { sortby: 'UID', sortdir: 'ASC' }),
                        dataSource: '../Handler/grid.ashx?view=vCost',
                    });
                },
                extraData: $.extend(defaultWhere, defaultSort),
                dataSource: "{rows:[],total:0}",
                colModel: colData
            });
            incomeGrid = $('#incomegrid').omGrid({
                width: '100%',
                height: 'fit',
                //title: '<span style="color:#15428B;font-weight: bold;padding:6px;">收入列表</span><span id="button-icdelete" style="float:right;text-align:center;cursor:pointer;"><img src="../Content/Images/List/delete.png" width="16" height="16" style="border:none;vertical-align:middle" />删除</span><span id="button-icedit" style="float:right;text-align:center;cursor:pointer;"><img src="../Content/Images/List/edit.png" width="16" height="16" style="border:none;vertical-align:middle" />编辑</span><span id="button-iccopy" style="float:right;text-align:center;cursor:pointer;"><img src="../Content/Images/List/copy.png" width="16" height="16" style="border:none;vertical-align:middle" />复制</span><span id="button-icnew" style="float:right;text-align:center;cursor:pointer;"><img src="../Content/Images/List/add.png" width="16" height="16" style="border:none;vertical-align:middle" />新增</span>',
                singleSelect: true,
                editMode: 'insert',
                limit: 20,
                extraData: $.extend({ where: ' 1=2 ' }, { sortby: 'UID', sortdir: 'ASC' }),
                dataSource: "{rows:[],total:0}",
                colModel: incomeColData
            });
            costGrid = $('#costgrid').omGrid({
                width: '100%',
                height: 'fit',
                //title: '<span style="color:#15428B;font-weight: bold;padding:6px;">成本列表</span><span id="button-codelete" style="float:right;text-align:center;cursor:pointer;"><img src="../Content/Images/List/delete.png" width="16" height="16" style="border:none;vertical-align:middle" />删除</span><span id="button-coedit" style="float:right;text-align:center;cursor:pointer;"><img src="../Content/Images/List/edit.png" width="16" height="16" style="border:none;vertical-align:middle" />编辑</span><span id="button-cocopy" style="float:right;text-align:center;cursor:pointer;"><img src="../Content/Images/List/copy.png" width="16" height="16" style="border:none;vertical-align:middle" />复制</span><span id="button-conew" style="float:right;text-align:center;cursor:pointer;"><img src="../Content/Images/List/add.png" width="16" height="16" style="border:none;vertical-align:middle" />新增</span>',
                singleSelect: true,
                editMode: 'insert',
                limit: 20,
                extraData: $.extend({ where: ' 1=2 ' }, { sortby: 'UID', sortdir: 'ASC' }),
                dataSource: "{rows:[],total:0}",
                colModel: costColData
            });
        });

        genRenderCheckbox = function (colValue, rowData, rowIndex) {
            if (colValue) {
                return '<input type="checkbox" id="00" checked="checked" disabled="disabled"></input>';
            }
            return '<input type="checkbox" id="01" disabled="disabled"></input>';
        }

        genRenderDateformatSS = function (colValue, rowData, rowIndex) {
            if (colValue.length == 0 || colValue == null) {
                return '';
            }
            else {
                if (colValue.indexOf("/Date") > -1)
                    return new Date(parseInt(colValue.replace("/Date(", "").replace(")/", ""), 10)).Format("yyyy-MM-dd");
                else
                    return colValue;
            }
        }

        genRenderDateformat = function (colValue, rowData, rowIndex) {
            if (colValue.length == 0 || colValue == null) {
                return '';
            }
            else {
                if (colValue.indexOf("/Date") > -1)
                    return new Date(parseInt(colValue.replace("/Date(", "").replace(")/", ""), 10)).Format("yyyy-MM-dd hh:mm");
                else
                    return colValue;
            }
        }

        showSearchPanel = function () {
            $("#CreateDateStart").omCalendar();
            $("#CreateDateEnd").omCalendar();
            //加载状态
            $.ajax({
                cache: false, async: false,
                url: "../Handler/combox.ashx?view=vBaseData",
                dataType: 'json', type: 'post',
                beforeSend: function () {
                    $.omMessageBox.waiting({
                        title: '请等待',
                        content: '服务器正在加载基础信息,请稍后...'
                    });
                },
                complete: function () {
                    $.omMessageBox.waiting("close");
                },
                success: function (data) {
                    comboxStatusData = []
                    $.each(data, function (index, value) {
                        switch (value.Type) {
                            case '账单状态':
                                comboxStatusData.push({ name: value.Name, code: value.Code, type: value.Type });
                                return true;
                            default:
                                return true;
                        }
                    })
                    $('#BillStatus', detailForm).omCombo({
                        dataSource: comboxStatusData,
                        valueField: 'name',
                        optionField: 'name',
                        inputField: 'name'
                    });
                },
                error: function (result) {
                    goOn = false;
                    $.omMessageBox.waiting("close");
                    $.omMessageBox.alert({
                        content: '发现错误<BR>：' + result.status
                    });
                }
            });
            $("#button-search").click(function () {
                var custWhere = '';
                if ($("#search-panel input[id='CreateDateStart']").val().length > 0) {
                    custWhere = " AND (CreateDate BETWEEN '" + $("#search-panel input[id='CreateDateStart']").val() + "' AND ";
                    if ($("#search-panel input[id='CreateDateEnd']").val().length > 0) {
                        custWhere += " '" + $("#search-panel input[id='CreateDateEnd']").val() + "') "
                    }
                    else {
                        custWhere += " GETDATE()) "
                    }
                }
                custWhere += ' AND OrderNo LIKE ' + '\'%' + $("#search-panel input[id='OrderNo']").val() + '%\'';
                //custWhere += ' AND CustomerCode LIKE ' + '\'%' + $("#search-panel input[id='CustomerCode']").val() + '%\'';
                ////custWhere += ' AND CustomerName LIKE ' + '\'%' + $("#search-panel input[id='CustomerName']").val() + '%\'';
                if ($("#search-panel input[id='BillStatus']").val().length > 0)
                    custWhere += " AND BillStatus = '" + $("#search-panel input[id='BillStatus']").val() + "'";
                listGrid.omGrid({
                    extraData: $.extend({ where: defaultWhere.where + custWhere }, defaultSort),
                    dataSource: '../Handler/grid.ashx?view=vBillVerify'
                });
                incomeGrid.omGrid({
                    extraData: $.extend({ where: defaultWhere.where + custWhere }, defaultSort),
                    dataSource: ''
                });
                costGrid.omGrid({
                    extraData: $.extend({ where: defaultWhere.where + custWhere }, defaultSort),
                    dataSource: ''
                });
            });
            $('#button-clear').click(function () {
                $("div[id='search-panel'] input").val("");
            });
            $('#button-verify').click(function () {
                if (listGrid[0].rows.length > 0) {
                    var selectRow = listGrid.omGrid("getSelections", true);
                    if (selectRow.length > 0) {
                        var tempuid = '';
                        $.each(selectRow, function (index, value) {
                            tempuid += value.UID + ',';
                        });
                        $.ajax({
                            cache: false, async: false,
                            url: '../handler/ajax.ashx?type=AjaxSystem&method=VerifyBill',
                            dataType: 'json', type: 'post',
                            data: { UID: tempuid.substring(0, tempuid.length - 1), USERID: currentUID },
                            beforeSend: function () {
                                $.omMessageBox.waiting({
                                    title: '请等待',
                                    content: '系统正在提交,请稍后...'
                                });
                            },
                            complete: function () {
                                $.omMessageBox.waiting("close");
                            },
                            success: function (data) {
                                if (data.IsError) {
                                    $.omMessageBox.alert({
                                        content: '错误：' + data.Message
                                    });
                                }
                                else {
                                    art.dialog.data('showValue', JSON2.parse(data.Data))
                                    art.dialog.open('../CheckPages/ShowBox.aspx', {
                                        id: 'selectDiv', width: 650, height: 400, title: '操作结果', lock: true,
                                        close: function () {
                                            listGrid.omGrid("reload");
                                        }
                                    }, false);
                                }
                            },
                            error: function (result) {
                                $.omMessageBox.alert({
                                    content: '发现错误<BR>：' + result.status
                                });
                            }
                        });
                    }
                    else {
                        $.omMessageBox.alert({
                            content: '请至少选择一条数据',
                            onClose: function () { }
                        });
                    }
                }
            });
            $('#button-undoverify').click(function () {
                if (listGrid[0].rows.length > 0) {
                    var selectundoRow = listGrid.omGrid("getSelections", true);
                    if (selectundoRow.length > 0) {
                        var tempuid = '';
                        $.each(selectundoRow, function (index, value) {
                            tempuid += value.UID + ',';
                        });
                        $.ajax({
                            cache: false, async: false,
                            url: '../handler/ajax.ashx?type=AjaxSystem&method=UndoVerifyBill',
                            dataType: 'json', type: 'post',
                            data: { UID: tempuid.substring(0, tempuid.length - 1), USERID: currentUID },
                            beforeSend: function () {
                                $.omMessageBox.waiting({
                                    title: '请等待',
                                    content: '系统正在提交,请稍后...'
                                });
                            },
                            complete: function () {
                                $.omMessageBox.waiting("close");
                            },
                            success: function (data) {
                                if (data.IsError) {
                                    $.omMessageBox.alert({
                                        content: '错误：' + data.Message
                                    });
                                }
                                else {
                                    art.dialog.data('showValue', JSON2.parse(data.Data))
                                    art.dialog.open('../CheckPages/ShowBox.aspx', {
                                        id: 'selectDiv', width: 650, height: 400, title: '操作结果', lock: true,
                                        close: function () {
                                            listGrid.omGrid("reload");
                                        }
                                    }, false);
                                }
                            },
                            error: function (result) {
                                $.omMessageBox.alert({
                                    content: '发现错误<BR>：' + result.status
                                });
                            }
                        });
                    }
                    else {
                        $.omMessageBox.alert({
                            content: '请至少选择一条数据',
                            onClose: function () { }
                        });
                    }
                }
            });
        };
    </script>
</head>
<body>
    <div id="west-panel" class="westpanel">
        <div id="search-panel">
            <table>
                <tr>
                    <td style="width: 70px" align="right">
                        <span class="label">创建时间</span>
                    </td>
                    <td>
                        <input type="text" class="input-text" id="CreateDateStart" />
                    </td>
                </tr>
                <tr>
                    <td style="width: 70px" align="right">
                        <span class="label">到</span>
                    </td>
                    <td>
                        <input type="text" class="input-text" id="CreateDateEnd" />
                    </td>
                </tr>
                <tr>
                    <td style="width: 70px" align="right">
                        <span class="label">账单状态</span>
                    </td>
                    <td>
                        <input type="text" class="input-text" id="BillStatus" />
                    </td>
                </tr>
                <tr>
                    <td style="width: 70px" align="right">
                        <span class="label">业务流水号</span>
                    </td>
                    <td>
                        <input type="text" class="input-text" id="OrderNo" />
                    </td>
                </tr>
                <tr>
                    <td style="width: 70px" align="right">
                        <span class="label">客户编号</span>
                    </td>
                    <td>
                        <input type="text" class="input-text" id="CustomerCode" />
                    </td>
                </tr>
                <tr>
                    <td style="width: 70px" align="right">
                        <span class="label">客户名称</span>
                    </td>
                    <td>
                        <input type="text" class="input-text" id="CustomerName" />
                    </td>
                </tr>
            </table>
        </div>
    </div>
    <div id="center-panel">
        <table id="listgrid"></table>
    </div>
    <div id="east-panel">
        <div style="height: 50%;">
            <table id="incomegrid"></table>
        </div>
        <div style="height: 50%;">
            <table id="costgrid"></table>
        </div>
    </div>
    <div id="south-panel">
        <table style="margin-top: 5px; margin-left: 20px;">
            <tr>
                <td>
                    <input id="button-search" type="button" class="btnCss" value="搜    索" />
                    <input id="button-clear" type="button" class="btnCss" value="清    空" style="margin-left: 20px;" />
                    <input id="button-verify" type="button" class="btnCss" value="审    核" style="margin-left: 20px;" />
                    <input id="button-undoverify" type="button" class="btnCss" value="取消审核" style="margin-left: 20px;" />
                </td>
            </tr>
        </table>
    </div>
</body>
</html>
